package com.cheyun.netsalev3.bean

import android.text.TextUtils
import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
import com.cheyun.netsalev3.BR
import com.cheyun.netsalev3.adapter.SecondaryListAdapter
import com.cheyun.netsalev3.bean.basedata.Infotype
import com.cheyun.netsalev3.utils.MySharedPreferences
import java.io.Serializable
import kotlin.collections.ArrayList


data class ClueDetails(
        var levelList: List<LevelList>,
        var Level: String,
        var addname: String,
        var address: String,
        var adduid: String,
        var arrive: String,
        var arrivenum: String,
        var arrivepeoplenum: String,
        var arrivetime: String,
        var brand: String,
        var brandgroup: String,
        var brandname: String,
        var buytype: String,
        var channel: String,
        var city: String,
        var competitor: List<String>,
        var competitorname: List<String>,
        var connectway: String,
        var connectwayname: String,
        var content: String,
        var county: String,
        var customerlevel: Int,
        var customerlevelname: String,
        var customertype: String,
        var dateline: String,
        var dbrand: String,
        var dbrandgroup: String,
        var dbrandname: String,
        var dccuid: String,
        var deliverexterior: String,
        var deliverexteriorname: String,
        var deliverStringerior: String,
        var deliverStringeriorname: String,
        var delivertime: String,
        var demand: String,
        var dlrff: String,
        var driving: String,
        var dseries: String,
        var dseriesname: String,
        var dspec: String,
        var dspecname: String,
        var dsuid: String,
        var effective: String,
        var endtime: String,
        var enduid: String,
        var exterior: String,
        var exteriorname: String,
        var exuid: String,
        var failurereason: String,
        var feedback: String,
        var fftime: String,
        var firstarrivetime: String,
        var follow: String,
        var followalarm: String,
        var followinfo: String,
        var followname: String,
        var followtime: String,
        var followuid: String,
        var ftime: String,
        var gcid: String,
        var giveupcause: String,
        var giveupcausename: String,
        var hide: String,
        var ibrand: String,
        var ibrandgroup: String,
        var ibrandname: String,
        var ibuytime: String,
        var ibuytimename: String,
        var infoplace: String,
        var infoplacename: String,
        var infosource: String,
        var infosourcename: String,
        var infotype: String,
        var infotypename: String,
        var instime: String,
        var insurer: String,
        var insurername: String,
        var Stringerior: String,
        var Stringeriorname: String,
        var invalid: String,
        var invalidname: String,
        var invitetime: String,
        var iorderid: String,
        var iseries: String,
        var iseriesname: String,
        var ispec: String,
        var ispecname: String,
        var lastname: String,
        var lastownername: String,
        var lastowneruid: String,
        var lastpost: String,
        var lastuid: String,
        var leavetime: String,
        var licenceplate: String,
        var loanbank: String,
        var loanbankname: String,
        var loanfee: String,
        var mlevel: String,
        var mlevelname: String,
        var mpuid: String,
        var nctime: String,
        var ncway: String,
        var ordernum: String,
        var ownername: String,
        var owneruid: String,
        var owntime: String,
        var paymentway: String,
        var paymentwayname: String,
        var pbrand: String,
        var pbrandgroup: String,
        var pbrandname: String,
        var phone: String,
        var phoneaddr: String,
        var plate: String,
        var policyno: String,
        var posttime: String,
        var price: String,
        var proctime: String,
        var province: String,
        var provincegroup: String,
        var pseries: String,
        var pseriesname: String,
        var purchasetype: String,
        var reception: String,
        var region: String,
        var remindetime: String,
        var schannel: String,
        var series: String,
        var seriesname: String,
        var sex: Int,
        var slogan: String,
        var sparephone: String,
        var spec: String,
        var specname: String,
        var state: String,
        var stated: String,
        var strikeexterior: String,
        var strikeexteriorname: String,
        var strikeStringerior: String,
        var strikeStringeriorname: String,
        var strikeprice: String,
        var supsales: String,
        var sysmsg: String,
        var tid: Int,
        var trackend: String,
        var tracktag: List<String>,
        var tracktagname: List<String>,
        var uname: String,
        var vas: String,
        var vin: String,
        var weixin: String,
        var interiorname: String,
        var strikeinteriorname: String,
        var deliverinteriorname: String,
        var strikeinterior: String,
        var deliverinterior: String,
        var ibrandgroupname: String,
        var is_out: String,
        var D_count:String,
        var call: Call,
        var interior:String,
        var hot:String,
        var cert_image_url:List<String>,
        var nol_customer_type:String, //大客户性质
        var nol_customer_name:String, //大客户名称
        var iscaddbuy:String,//保有客户增购
        var iscrecom:String,//保有客户转介绍
        var is_car_exchange:String,//二手车置换
        var recommend_code:String,//推荐人
        var recommend_name:String,//推荐人姓名
        var recommend_phone:String,//推荐人手机号
        var recommend_vin:String, //推荐人底盘号
        var recommend_spec:String, //推荐车型
        var productname:String, //意向产品名称
        var iproductname:String, //成交产品名称
        var dproductname:String, //提车产品名称
        var tracktagname_offline:List<String>, //线下标签列表
        var tracktagname_online:List<String>, //线上标签列表
        var tracktag_offline:List<String>, //线下标签列表
        var tracktag_online:List<String>, //线上标签列表
        var cardtype:String,
        var cardno:String,
        var birthday:String,
        var aic:String,
        var aicname:String,
        var plan_vin:String,
        var ce_no:String,
        var engine_no:String,
        var son:String,
        var warehouse:String,
        var offline_date:String,
        var delivery_date:String,
        var promise_delivery_date:String,
        var gplace:String,
        var readonlytags:List<String>, //只读标签列表
        var drivestime:String,
        var realspec:String,
        var realseries:String,
        var reserveid:String,
        var reservetime:String,
        var reservecustomerlevelikey:String,
        var reservecustomerlevelid:String,
        var reservencwayikey:String,
        var reservencwayid:String,
        var reservestoreitemsikey:String,
        var reservestoreitemsid:String,
        var reservename:String,
        var reservephone:String,
        var sysdrive:Int,
        var adorder:Int,
        var recordVoice:String = "",
        var isapp:Int = 0,
        var xphone:String = "",
        var spec_select:Int = 1,
        var appminiorder:Int = 0,
        var followstatename:String = "",
        var followstate:Int = 0,
        var alllabels:List<Infotype>,
        val drivingisarrive:Int = 0,
        val provincename:String = "",
        val cityname:String = "",
        val countyname:String = "",
        val secseries:String = "",
        val secspec:String = "",
        val secssgroup:String = "",
        val secspecname:String = "",
        val secseriesname:String = ""


) : BaseObservable(), Serializable {

    @get:Bindable
    var isfocus: Int = 0
        set(isfocus) {
            field = isfocus
            notifyPropertyChanged(BR.isfocus)
        }

    //个人信息
    var baseDatakey = arrayOf(
            "姓         名:",
            "电         话:",
            "客户编号:",
            "线索创建时间:",
            "性         别:",
            "线索类型:",
            "触点渠道:",
            "信息来源:",
//            "拟购时间:",
//            "拟购品牌:",
            "意向车系:",
            "意向车型:",
            "意向车辆颜色:",
            "意向内饰颜色:",
            "拟上本地车牌:",
            "促销内容:",
            "备         注:",
            "系统备注:",
            "竞品信息:,",
            "大客户性质",
            "大客户名称",
            "二手车置换",
            "是否保有客户增购",
            "是否保有客户转介绍",
            "推荐人",
            "推荐人姓名",
            "推荐人手机号",
            "推荐人底盘号",
            "推荐车型")
    //附加信息
    var fujiaDatakey = arrayOf(
            "客户类型:",
            "购买类型:",
            "预购台数:",
            "号码归属地:",
            "备用电话:",
            "微  信  号:",
            "现用品牌:",
            "现用车系:",
            "地        区:",
            "具体地址:",
            "线上标签:",
            "线下标签:")
    //行为记录
    var xinweiDatakey = arrayOf(
            "有效性判断:",
            "线索无效原因:",
            "预约到店时间:",
//            "最近来店时间:",
            "最近离店时间:",
            "接待时长:",
//            "来店人数:",
            "是否到店:",
            "是否试驾:",
            "来店次数:",
            "首次来店时间:",
            "战败时间:",
            "战败原因:",
            "战败原因分析:")


    //流转记录
    var liuzhuanDatakey = arrayOf(
            "线索拥有者:",
            "最后操作人:",
            "集客人:",
            "邀约人:",
            "引导人:",
            "接待人:"
    )

    //跟进记录
    var zuizhongDatakey = arrayOf(
            "跟进人:",
            "跟进时间:",
            "跟进方式:",
            "跟进级别:",
            "本次报价:",
            "跟进情况:",
            "mor"

    )
    //通话记录
    var tonghuaDatakey = arrayOf(
            "通话类型:",
            "开始时间:",
            "通话时长:",
            "通话结果:",
            "mor"

    )

    var dataslist = ArrayList<SecondaryListAdapter.DataTree<String, KeyValueParam>>()
    var datelinename = ""
    var effectivename = ""

    fun xiaodingChangeSeries():Boolean{
        if(appminiorder > 0 && seriesname?.length > 0){
            return false
        }
        return true
    }

    fun xiaodingChangeSpec():Boolean{
        if(appminiorder > 0 && specname?.length > 0){
            return false
        }
        return true
    }

    fun getData() {
        datelinename = dateline
        dataslist.clear()
        var s = "未知"
        if(sex.equals("1"))
            s = "男"
        else if(sex.equals("2"))
            s = "女"
        var baseDatavalue = arrayOf(
                uname,
                xphone,
                iorderid,
                dateline,
                s,
                infotypename,
                infoplacename,
                infosourcename,
//                ibuytimename,
//                brandname,
                if(seriesname ==null)"" else seriesname,
                if(specname ==null)"" else specname,
                exteriorname,
                interiorname,
                if (licenceplate.equals("1")) "是" else "否",
                slogan,
                content,
                sysmsg,
                TextUtils.join(",",competitorname),
                nol_customer_type,
                nol_customer_name,
                is_car_exchange,
                iscaddbuy,
                iscrecom,
                recommend_code,
                recommend_name,
                recommend_phone,
                recommend_vin,
                recommend_spec)



        //1:个人；2:公司；3:行政单位
        var customertypenanme = when (customertype) {
            "1" -> "个人"
            "2" -> "公司"
            "3" -> "行政单位"
            else -> {
                ""
            }
        }
        //  1, //购买类型，1:首购；2:增购；3:置换
        var purchasetypename = when (purchasetype) {
            "1" -> "首购"
            "2" -> "增购"
            "3" -> "置换"
            else -> {
                ""
            }
        }
        var fujiaDatavalue = arrayOf(
                customertypenanme,
                purchasetypename,
                demand,
                phoneaddr,
                sparephone,
                weixin,
                pseriesname,
                pbrandname,
                region,
                address,
                TextUtils.join(",",tracktagname_online),
                TextUtils.join(",",tracktagname_offline))
        //  0:继续跟进；1:有效；2:无效
        effectivename = when (effective) {
            "0" -> "待判定"
            "1" -> "有效"
            "2" -> "无效"
            else -> {
                ""
            }
        }
        //是否到店，0:未到店；1:已到店
        var arrivename = when (arrive) {
            "0" -> "否"
            "1" -> "是"

            else -> {
                ""
            }
        }

        //是否试驾，0:否；1:是
        var drivingname = when (driving) {
            "0" -> "否"
            "1" -> "是"

            else -> {
                ""
            }
        }
        //行为记录
        var xinweiDatavalue = arrayOf(
                effectivename,
                invalidname,
                invitetime,
//                arrivetime,
                leavetime,
                reception,
//                arrivepeoplenum,
                arrivename,
                drivingname,
                arrivenum,
                firstarrivetime,
                lastpost,
                giveupcausename,
                failurereason)

        //购车记录
        var goucarDatavalue = arrayOf(
//                ibrandname,
                iseriesname,
                ispecname,
                endtime,
                ordernum,
                strikeprice,
                strikeexteriorname,
                strikeinteriorname,
                delivertime,
                plate,
                vin,
                insurername,
                policyno,
                instime,
                paymentwayname,
                loanbankname,
                loanfee,
                supsales,
                mlevelname,
                vas,
                dbrandname,
                dseriesname,
                dspecname,
                deliverexteriorname,
                deliverinteriorname
        )
        //购车记录
        var goucarDatakey = arrayOf(
//                "订车品牌:",
                "订车车系:",
                "订车车型:",
                "预定成交时间:",
                "订单号:",
                "预订价格:",
                "订车车辆颜色:",
                "订车内饰颜色:",
                "提车时间:",
                "车牌号:",
                "车架号:",
                "保险公司:",
                "保单号:",
                "保险到期日:",
                "付款方式:",
                "按揭银行:",
                "按揭服务费:",
                "用品销售额:",
                "会员:",
                "其他费用:",
                "提车品牌:",
                "提车车系:",
                "提车车型:",
                "提车车辆颜色:",
                "提车内饰颜色:"
        )
        //购车记录传参名称
        var goucarDataIdName = arrayOf(
//                "ibrand",
                "iseries",
                "ispec",
                "endtime",
                "ordernum",
                "strikeprice",
                "strikeexterior",
                "strikeinterior",
                "delivertime",
                "plate",
                "vin",
                "insurer",
                "policyno",
                "instime",
                "paymentway",
                "loanbank",
                "loanfee",
                "supsales",
                "mlevel",
                "vas",
                "dbrand",
                "dseries",
                "dspec",
                "deliverexterior",
                "deliverinterior"
        )
        //购车记录传参默认值
        var goucarDataId = arrayOf(
//                ibrand,
                iseries,
                ispec,
                endtime,
                ordernum,
                strikeprice,
                strikeexterior,
                strikeinterior,
                delivertime,
                plate,
                vin,
                insurer,
                policyno,
                instime,
                paymentway,
                loanbank,
                loanfee,
                supsales,
                mlevel,
                vas,
                dbrand,
                dseries,
                dspec,
                deliverexterior,
                deliverinterior
        )

        //流转记录
        var liuzhuanDatavalue = arrayOf(
                ownername,
                lastname,
                "集客人:",
                "邀约人:",
                "引导人:",
                "接待人:"
        )

        //跟进记录
        var zuizhongDatavalue = arrayOf(
                followname, followtime, connectwayname, Level, price, followinfo, ""

        )
        var calltype = when (call.calltype) {
            0 -> "其他"
            1 -> "去电"
            2 -> "来电"
            else -> ""
        }
        var callstate = when (call.state) {
            "1" -> "接通"
            "0" -> "未接通"
            else -> ""
        }
        //通话记录
        var tonghuaDatavalue = arrayOf(
                calltype,
                call.starttime,
                call.times,
                callstate,
                ""

        )

        dataslist.add(SecondaryListAdapter.DataTree("基本信息", object : ArrayList<KeyValueParam>() {
            init {
                for (i in 0 until baseDatakey.size) {
                    add(KeyValueParam(baseDatakey[i], baseDatavalue[i]))
                }
            }
        }))
        dataslist.add(SecondaryListAdapter.DataTree("附加信息", object : ArrayList<KeyValueParam>() {
            init {
                for (i in 0 until fujiaDatakey.size) {
                    if (fujiaDatavalue[i] == null) {
                        add(KeyValueParam(fujiaDatakey[i], ""))
                    } else {
                        add(KeyValueParam(fujiaDatakey[i], fujiaDatavalue[i].toString()))
                    }

                }
            }
        }))
        dataslist.add(SecondaryListAdapter.DataTree("行为记录", object : ArrayList<KeyValueParam>() {
            init {
                for (i in 0 until xinweiDatakey.size) {
                    add(KeyValueParam(xinweiDatakey[i], xinweiDatavalue[i] ?: ""))
                }
            }
        }))
        if (!endtime.isNullOrBlank() && endtime != "0") {
            dataslist.add(SecondaryListAdapter.DataTree("购车记录", object : ArrayList<KeyValueParam>() {
                init {
                    for (i in 0 until goucarDatakey.size) {
                        var item = KeyValueParam(goucarDatakey[i], goucarDatavalue[i] ?: "")
                        item.idname = goucarDataIdName[i]
                        item.id = goucarDataId[i]
                        add(item)
                    }
                }
            }))
        }
        if (!fftime.isNullOrBlank() && fftime != "0") {
            dataslist.add(SecondaryListAdapter.DataTree("跟进记录", object : ArrayList<KeyValueParam>() {
                init {
                    for (i in 0 until zuizhongDatakey.size) {
                        add(KeyValueParam(zuizhongDatakey[i], zuizhongDatavalue[i].toString()))
                    }
                }
            }))
        }

        dataslist.add(SecondaryListAdapter.DataTree("通话记录", object : ArrayList<KeyValueParam>() {
            init {
                for (i in 0 until tonghuaDatakey.size) {
                    add(KeyValueParam(tonghuaDatakey[i], tonghuaDatavalue[i].toString()))
                }
            }
        }))

        //是否开启库存
        var state = MySharedPreferences.getLoginData()?.channel?.settings?.storage?.state ?: 0
        var isedit = !(!vin.isNullOrBlank() && state == 1)
        var dingCarlist = arrayOf(
//                KeyValueParam("提车品牌:", 1, "dbrand", value = dbrandname, id = dbrand,isEdit = isedit),
                KeyValueParam("提车车系:", 1, "dseries", value = dseriesname, id = dseries,isEdit = isedit),
                KeyValueParam("提车车型:", 1, "dspec", value = dspecname, id = dspec,isEdit = isedit),
                KeyValueParam("提车时间:", 1, "delivertime", 2, value = delivertime, id = delivertime),
                KeyValueParam("车架号:", 2, "vin", value = vin, id = vin,isEdit = isedit),
                KeyValueParam("车牌号:", 2, "plate", value = plate, id = plate),
                KeyValueParam("提车车辆颜色:", 1, "deliverexterior", value = deliverexteriorname, id = deliverexterior,isEdit = isedit),
                KeyValueParam("提车内饰颜色:", 1, "deliverinterior", value = deliverinteriorname, id = deliverinterior,isEdit = isedit),
                KeyValueParam("购买类型:", 1, "purchasetype", value = purchasetypename, id = purchasetype),
                KeyValueParam("保险公司:", 1, "insurer", value = insurername, id = insurer),
                KeyValueParam("保单号:", 2, "policyno", value = policyno, id = policyno)
        )
        liftCarlist.addAll(dingCarlist)



        var temBuyCarlist = arrayOf(
                KeyValueParam("预定车系:", 1, "iseries", value = iseriesname, id = iseries,isEdit = true),
                KeyValueParam("预定车型:", 1, "ispec", value = ispecname, id = ispec,isEdit = true),
                KeyValueParam("预定车辆颜色:", 1, "strikeexterior", value = strikeexteriorname, id = strikeexterior,isEdit = true),
                KeyValueParam("预定车辆内饰颜色:", 1, "strikeinterior", value = strikeinteriorname, id = strikeinterior,isEdit = true),
                KeyValueParam("证件类型:", 1, "cardtype", value = cardtype, id = cardtype,isEdit = true),
                KeyValueParam("证件号码:", 1, "cardno", 2, value = cardno, id = cardno),
                KeyValueParam("生日:", 1, "birthday", 2, value = birthday, id = birthday),
                KeyValueParam("订单号:", 2, "ordernum", value = ordernum, id = ordernum),
                KeyValueParam("实际VIN:", 2, "vin", value = vin, id = vin),
                KeyValueParam("产品编码:", 2, "aic", value = aic, id = aic),
                KeyValueParam("产品名称:", 2, "iproductname", value = iproductname, id = iproductname),
                KeyValueParam("预匹配VIN:", 2, "plan_vin", value = plan_vin, id = plan_vin),
                KeyValueParam("合格证号:", 2, "ce_no", value = ce_no, id = ce_no),
                KeyValueParam("发动机编号:", 2, "engine_no", value = engine_no, id = engine_no),
                KeyValueParam("SON:", 2, "son", value = son, id = son),
                KeyValueParam("发车仓库名称:", 2, "warehouse", value = warehouse, id = warehouse),
                KeyValueParam("预计下线时间:", 2, "offline_date", value = offline_date, id = offline_date),
                KeyValueParam("承诺交付日:", 2, "promise_delivery_date", value = promise_delivery_date, id = promise_delivery_date)

        )
        buyCarlist.addAll(temBuyCarlist)
    }

    var liftCarlist = ArrayList<KeyValueParam>()
    var buyCarlist = ArrayList<KeyValueParam>()

    constructor() : this(ArrayList<LevelList>(),

            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            ArrayList<String>(),
            ArrayList<String>(),
            "",
            "",
            "",
            "",
            0,
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            0,
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            0,
            "",
            ArrayList<String>(),
            ArrayList<String>(),
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            Call(),
            "",
            "0",
            ArrayList<String>(),
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            ArrayList<String>(),
            ArrayList<String>(),
            ArrayList<String>(),
            ArrayList<String>(),
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            ArrayList<String>(),
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            0,
            0,"",0,"",0,0,"",0,ArrayList<Infotype>()

    )
}